package server;

import main.CommonMethods;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
import org.apache.xmlrpc.common.XmlRpcHttpRequestConfig;
import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping.AuthenticationHandler;

/**
 * This class handles authentication for the RPC-Server
 * 
 * 
 */
public class BotAuthenticationHandler implements AuthenticationHandler {

   private boolean isAuthenticated(final String basicUserName, final String basicPassword) {
	  return CommonMethods.loginBotAccount(basicUserName, basicPassword);
   }

   @Override
   public boolean isAuthorized(final XmlRpcRequest pRequest) throws XmlRpcException {
	  XmlRpcHttpRequestConfig config = (XmlRpcHttpRequestConfig) pRequest.getConfig();
	  return isAuthenticated(config.getBasicUserName(), config.getBasicPassword());
   }
}
